package com.yidu.StockControl.service.impl;


import com.yidu.StockControl.entity.CashInventory;
import com.yidu.StockControl.mapper.CashInventoryMapper;
import com.yidu.StockControl.service.CashInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CashInventoryServiceImpl implements CashInventoryService {
    @Autowired
    CashInventoryMapper cashInventoryMapper;

    @Override
    public List<CashInventory> selectCashInventory(String cashInventoryTime,String businessType, int page, int limit) {
        System.out.println("查询");
        Map map = new HashMap();
        map.put("strWhere",buildWhere(cashInventoryTime,businessType));
        map.put("page",(page-1)*limit);
        map.put("limit",page*limit);
        return cashInventoryMapper.selectCashInventory(map);
    }
    public String buildWhere (String cashInventoryTime,String businessType) {
        StringBuffer strWhere = new StringBuffer();

        if (cashInventoryTime!=null && !cashInventoryTime.equals("")){
            strWhere.append(" and cashInventoryTime like '%" + cashInventoryTime +"%'" );
        }
        if (businessType!=null && !businessType.equals("")){
            strWhere.append(" and businessType like '%" + businessType +"%'" );
        }
        return strWhere.toString();
    }

    @Override
    public int insertCashInventory(CashInventory cashInventory) {
        return cashInventoryMapper.insertCashInventory(cashInventory);
    }

    @Override
    public void updateCashInventory(CashInventory cashInventory) {
       cashInventoryMapper.updateCashInventory(cashInventory);
    }

    @Override
    public void deleteCashInventory(String cashInventoryId) {
        cashInventoryMapper.deleteCashInventory(cashInventoryId);

    }

    @Override
    public int selectCashInventoryCount() {
        return cashInventoryMapper.selectCashInventoryCount();
    }


}
